home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / readline.lha / readline / funmap.c < prev    next >
C/C++ Source or Header  |  1991-01-19  |  7KB  |  215 lines

  1. /* funmap.c -- attach names to functions. */
  2.  
  3. /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by the
  10.    Free Software Foundation; either version 1, or (at your option) any
  11.    later version.
  12.  
  13.    Readline is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with Readline; see the file COPYING.  If not, write to the Free
  20.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. #define STATIC_MALLOC
  23. #ifndef STATIC_MALLOC
  24. extern char *xmalloc (), *xrealloc ();
  25. #else
  26. static char *xmalloc (), *xrealloc ();
  27. #endif
  28.  
  29. #ifndef BUFSIZ
  30. #include <stdio.h>
  31. #endif /* BUFSIZ */
  32.  
  33. #include "readline.h"
  34.  
  35. FUNMAP **funmap = (FUNMAP **)NULL;
  36. static int funmap_size = 0;
  37. static int funmap_entry = 0;
  38.  
  39. static FUNMAP default_funmap[] = {
  40.   { "arrow-key-prefix", rl_arrow_keys },
  41.   { "redraw-current-line", rl_refresh_line},
  42.   { "beginning-of-line", rl_beg_of_line },
  43.   { "backward-char", rl_backward },
  44.   { "delete-char", rl_delete },
  45.   { "end-of-line", rl_end_of_line },
  46.   { "forward-char", rl_forward },
  47.   { "accept-line", rl_newline },
  48.   { "kill-line", rl_kill_line },
  49.   { "clear-screen", rl_clear_screen },
  50.   { "next-history", rl_get_next_history },
  51.   { "previous-history", rl_get_previous_history },
  52.   { "quoted-insert", rl_quoted_insert },
  53.   { "reverse-search-history", rl_reverse_search_history },
  54.   { "forward-search-history", rl_forward_search_history },
  55.   { "transpose-chars", rl_transpose_chars },
  56.   { "unix-line-discard", rl_unix_line_discard },
  57.   { "unix-word-rubout", rl_unix_word_rubout },
  58.   { "yank", rl_yank },
  59.   { "yank-pop", rl_yank_pop },
  60.   { "yank-nth-arg", rl_yank_nth_arg },
  61.   { "backward-delete-char", rl_rubout },
  62.   { "backward-word", rl_backward_word },
  63.   { "kill-word", rl_kill_word },
  64.   { "forward-word", rl_forward_word },
  65.   { "tab-insert", rl_tab_insert },
  66.   { "backward-kill-word", rl_backward_kill_word },
  67.   { "backward-kill-line", rl_backward_kill_line },
  68.   { "transpose-words", rl_transpose_words },
  69.   { "digit-argument", rl_digit_argument },
  70.   { "complete", rl_complete },
  71.   { "possible-completions", rl_possible_completions },
  72.   { "do-lowercase-version", rl_do_lowercase_version },
  73.   { "digit-argument", rl_digit_argument },
  74.   { "universal-argument", rl_universal_argument },
  75.   { "abort", rl_abort },
  76.   { "undo", rl_undo_command },
  77.   { "upcase-word", rl_upcase_word },
  78.   { "downcase-word", rl_downcase_word },
  79.   { "capitalize-word", rl_capitalize_word },
  80.   { "revert-line", rl_revert_line },
  81.   { "beginning-of-history", rl_beginning_of_history },
  82.   { "end-of-history", rl_end_of_history },
  83.   { "self-insert", rl_insert },
  84.   { "start-kbd-macro", rl_start_kbd_macro },
  85.   { "end-kbd-macro", rl_end_kbd_macro },
  86.   { "re-read-init-file", rl_re_read_init_file },
  87. #ifdef VI_MODE
  88.   { "vi-movement-mode", rl_vi_movement_mode },
  89.   { "vi-insertion-mode", rl_vi_insertion_mode },
  90.   { "vi-arg-digit", rl_vi_arg_digit },
  91.   { "vi-prev-word", rl_vi_prev_word },
  92.   { "vi-next-word", rl_vi_next_word },
  93.   { "vi-char-search", rl_vi_char_search },
  94.   { "vi-editing-mode", rl_vi_editing_mode },
  95.   { "vi-eof-maybe", rl_vi_eof_maybe },
  96.   { "vi-append-mode", rl_vi_append_mode },
  97.   { "vi-put", rl_vi_put },
  98.   { "vi-append-eol", rl_vi_append_eol },
  99.   { "vi-insert-beg", rl_vi_insert_beg },
  100.   { "vi-delete", rl_vi_delete },
  101.   { "vi-comment", rl_vi_comment },
  102.   { "vi-first-print", rl_vi_first_print },
  103.   { "vi-fword", rl_vi_fword },
  104.   { "vi-fWord", rl_vi_fWord },
  105.   { "vi-bword", rl_vi_bword },
  106.   { "vi-bWord", rl_vi_bWord },
  107.   { "vi-eword", rl_vi_eword },
  108.   { "vi-eWord", rl_vi_eWord },
  109.   { "vi-end-word", rl_vi_end_word },
  110.   { "vi-change-case", rl_vi_change_case },
  111.   { "vi-match", rl_vi_match },
  112.   { "vi-bracktype", rl_vi_bracktype },
  113.   { "vi-change-char", rl_vi_change_char },
  114.   { "vi-yank-arg", rl_vi_yank_arg },
  115.   { "vi-search", rl_vi_search },
  116.   { "vi-search-again", rl_vi_search_again },
  117.   { "vi-dosearch", rl_vi_dosearch },
  118.   { "vi-subst", rl_vi_subst },
  119.   { "vi-overstrike", rl_vi_overstrike },
  120.   { "vi-overstrike-delete", rl_vi_overstrike_delete },
  121.   { "vi-replace, ", rl_vi_replace },
  122.   { "vi-column", rl_vi_column },
  123.   { "vi-delete-to", rl_vi_delete_to },
  124.   { "vi-change-to", rl_vi_change_to },
  125.   { "vi-yank-to", rl_vi_yank_to },
  126.   { "vi-complete", rl_vi_complete },
  127. #endif /* VI_MODE */
  128.  
  129.  {(char *)NULL, (Function *)NULL }
  130. };
  131.  
  132. rl_add_funmap_entry (name, function)
  133.      char *name;
  134.      Function *function;
  135. {
  136.   if (funmap_entry + 2 >= funmap_size)
  137.     if (!funmap)
  138.       funmap = (FUNMAP **)xmalloc ((funmap_size = 80) * sizeof (FUNMAP *));
  139.     else
  140.       funmap =
  141.     (FUNMAP **)xrealloc (funmap, (funmap_size += 80) * sizeof (FUNMAP *));
  142.   
  143.   funmap[funmap_entry] = (FUNMAP *)xmalloc (sizeof (FUNMAP));
  144.   funmap[funmap_entry]->name = name;
  145.   funmap[funmap_entry]->function = function;
  146.  
  147.   funmap[++funmap_entry] = (FUNMAP *)NULL;
  148. }
  149.  
  150. static int funmap_initialized = 0;
  151.  
  152. /* Make the funmap contain all of the default entries. */
  153. rl_initialize_funmap ()
  154. {
  155.   register int i;
  156.  
  157.   if (funmap_initialized)
  158.     return;
  159.  
  160.   for (i = 0; default_funmap[i].name; i++)
  161.     rl_add_funmap_entry (default_funmap[i].name, default_funmap[i].function);
  162.  
  163.   funmap_initialized = 1;
  164. }
  165.  
  166. /* Things that mean `Control'. */
  167. char *possible_control_prefixes[] = {
  168.   "Control-", "C-", "CTRL-", (char *)NULL
  169. };
  170.  
  171. char *possible_meta_prefixes[] = {
  172.   "Meta", "M-", (char *)NULL
  173. };
  174.  
  175. #ifdef STATIC_MALLOC
  176.  
  177. /* **************************************************************** */
  178. /*                                    */
  179. /*            xmalloc and xrealloc ()                     */
  180. /*                                    */
  181. /* **************************************************************** */
  182.  
  183. static void memory_error_and_abort ();
  184.  
  185. static char *
  186. xmalloc (bytes)
  187.      int bytes;
  188. {
  189.   char *temp = (char *)malloc (bytes);
  190.  
  191.   if (!temp)
  192.     memory_error_and_abort ();
  193.   return (temp);
  194. }
  195.  
  196. static char *
  197. xrealloc (pointer, bytes)
  198.      char *pointer;
  199.      int bytes;
  200. {
  201.   char *temp = (char *)realloc (pointer, bytes);
  202.  
  203.   if (!temp)
  204.     memory_error_and_abort ();
  205.   return (temp);
  206. }
  207.  
  208. static void
  209. memory_error_and_abort ()
  210. {
  211.   fprintf (stderr, "history: Out of virtual memory!\n");
  212.   abort ();
  213. }
  214. #endif /* STATIC_MALLOC */
  215.